package com.ruoyi.web.controller.system;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SysAppPrescriptionInfo;
import com.ruoyi.system.domain.SysAppPrescriptionSort;
import com.ruoyi.system.service.ISysAppPrescriptionInfoService;
import com.ruoyi.system.service.ISysAppPrescriptionSortService;
import com.ruoyi.web.controller.form.InfoSortForm;
import com.ruoyi.web.controller.form.PrescriptionInfoMedicineForm;

/**
 * 方剂信息内容Controller
 * 
 * @author ruoyi
 * @date 2020-09-05
 */
@Controller
@RequestMapping("/system/info")
public class SysAppPrescriptionInfoController extends BaseController {
	private String prefix = "system/info";

	@Autowired
	private ISysAppPrescriptionSortService sysAppPrescriptionSortService;

	@Autowired
	private ISysAppPrescriptionInfoService sysAppPrescriptionInfoService;

	@RequiresPermissions("system:info:view")
	@GetMapping()
	public String info() {
		return prefix + "/info";
	}

	/**
	 * 查询方剂信息内容列表
	 */
	@RequiresPermissions("system:info:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(SysAppPrescriptionInfo sysAppPrescriptionInfo) {
		startPage();
		List<SysAppPrescriptionInfo> list = sysAppPrescriptionInfoService
				.selectSysAppPrescriptionInfoList(sysAppPrescriptionInfo);
		return getDataTable(list);
	}

	/**
	 * 导出方剂信息内容列表
	 */
	@RequiresPermissions("system:info:export")
	@Log(title = "方剂信息内容", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	@ResponseBody
	public AjaxResult export(SysAppPrescriptionInfo sysAppPrescriptionInfo) {
		List<SysAppPrescriptionInfo> list = sysAppPrescriptionInfoService
				.selectSysAppPrescriptionInfoList(sysAppPrescriptionInfo);
		ExcelUtil<SysAppPrescriptionInfo> util = new ExcelUtil<SysAppPrescriptionInfo>(SysAppPrescriptionInfo.class);
		return util.exportExcel(list, "info");
	}

	/**
	 * 新增方剂信息内容
	 */
	@GetMapping("/add")
	public String add() {
		return prefix + "/add";
	}

	/**
	 * 新增保存方剂信息内容
	 */
	@RequiresPermissions("system:info:add")
	@Log(title = "方剂信息内容", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(SysAppPrescriptionInfo sysAppPrescriptionInfo) {
		return toAjax(sysAppPrescriptionInfoService.insertSysAppPrescriptionInfo(sysAppPrescriptionInfo));
	}

	/**
	 * 修改方剂信息内容
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap) {
		SysAppPrescriptionInfo sysAppPrescriptionInfo = sysAppPrescriptionInfoService
				.selectSysAppPrescriptionInfoById(id);
		mmap.put("sysAppPrescriptionInfo", sysAppPrescriptionInfo);
		return prefix + "/edit";
	}

	@GetMapping("/goSort/{id}")
	public String goSort(@PathVariable("id") Long id, ModelMap mmap) {
		SysAppPrescriptionInfo sysAppPrescriptionInfo = sysAppPrescriptionInfoService
				.selectSysAppPrescriptionInfoById(id);
		mmap.put("sysAppPrescriptionInfo", sysAppPrescriptionInfo);
		return prefix + "/addSort";
	}
	
	


	/**
	 * 修改保存方剂信息内容
	 */
	@RequiresPermissions("system:info:edit")
	@Log(title = "方剂信息内容", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(SysAppPrescriptionInfo sysAppPrescriptionInfo) {
		return toAjax(sysAppPrescriptionInfoService.updateSysAppPrescriptionInfo(sysAppPrescriptionInfo));
	}

	/**
	 * 删除方剂信息内容
	 */
	@RequiresPermissions("system:info:remove")
	@Log(title = "方剂信息内容", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(sysAppPrescriptionInfoService.deleteSysAppPrescriptionInfoByIds(ids));
	}

	/**
	 * 查询字典详细
	 */
	@GetMapping("/detail/{infoId}")
	public String detail(@PathVariable("infoId") Long infoId, ModelMap mmap) {
		mmap.put("prescriptionInfo", sysAppPrescriptionInfoService.selectSysAppPrescriptionInfoById(infoId));
		return "system/prescriptioninfomedicine/medicine";
	}

	/**
	 * 添加方剂信息
	 */
	@GetMapping("/goMedicine/{id}")
	public String goMedicine(@PathVariable("id") Long id, ModelMap mmap) {
		SysAppPrescriptionInfo info = sysAppPrescriptionInfoService.selectSysAppPrescriptionInfoById(id);
		mmap.put("sysAppPrescriptionInfo", info);
		return prefix + "/addMedicine";
	}

	/**
	 * 新增方剂信息
	 */
	@PostMapping("/saveMedicine")
	@ResponseBody
	public AjaxResult saveMedicine(PrescriptionInfoMedicineForm form) {

		return toAjax(1);
	}
	
	@PostMapping("/selectInfoBySortId")
	@ResponseBody
	public TableDataInfo selectInfoBySortId(InfoSortForm form) {
		Long infoId = form.getSortId();
		List<SysAppPrescriptionInfo> list = sysAppPrescriptionInfoService.selectInfoBySortId(infoId);
		return getDataTable(list);
	}
	
}
